import apiHelp from '@/utils/apiHelp.js'
const actions = {
	async loadGlobalData({
		getters,
		commit
	}) {
		let data = await apiHelp.loadSpotList(getters.token);
		commit('SET_SPOTLIST', data);
	},
	//身份验证:验证失败则跳转登录页面
	checkIndentity({
		getters,
		commit
	}) {
		if (getters.openid.length == 0 || getters.token.length == 0) {
			//身份不通过，跳转登录页面
			uni.redirectTo({
				url: "/pages/index/index"
			})
			return false;
		}
		return true;
	},
	//角色页面跳转
	async roleToPage({
		getters,
		commit,
		dispatch
	}) {
		switch (true) {
			case (getters.switch_1.length == 1): {
				switch (true) {
					case (getters.switch_2.length == 0):
						//单角色，单人员
						//加载菜单
						await dispatch('changeRole', {
							key: getters.switch_1[0],
							value: getters.switch_3
						});
						//跳转页面
						commit('SET_ROLE', getters.switch_1[0]);
						let page = getters.index;
						uni.switchTab({
							url: page
						});
						break;
					case (getters.switch_2.length > 0):
						//单角色，多人员
						uni.redirectTo({
							url: "/pages/operator/operator"
						});
						return true;
						break;
				}
				break;
			}
			case (getters.switch_1.length > 1): {
				//多角色
				uni.redirectTo({
					url: "/pages/role/role"
				});
				break;
			}
		}
	}
}

export default actions